Skip to content

fix(update): resume an interrupted download - #28

Closed
xiaoyumuxi wants to merge 1 commit into
mainfrom
lithe/update-download-resume-on-main
Closed

xiaoyumuxi wants to merge 1 commit into
mainfrom
lithe/update-download-resume-on-main

Conversation

@xiaoyumuxi

Copy link
Copy Markdown

Problem

Lithe's update download started from zero again after any interruption. update.Download and DownloadPatch removed the temporary file on every failure, including a dropped connection. Nothing ended a connection that went silent either: the archive client has no total timeout, so a connection that stopped sending held the download until the window was closed.

Lithe also could not tell a cut-off patch download from a bad patch. Both made it fall back to the full archive, which is the larger download.

Change

  • Resume. An interrupted transfer keeps its bytes in a hidden .viva-update-<sha256>.part file in the download directory. The next call sends Range: bytes=N- for the rest.
    • A 200 starts the file over.
    • A 206 for another part, or a 416, asks once more for the whole file.
    • The whole file is hashed again before it is kept. Kept bytes that fail the check are fetched once more from scratch.
  • ErrInterrupted. It is returned for a failed connection, nothing arriving for a minute, 408, 429 or 5xx, or the end of ctx (the error wraps the context's error too).
  • A verified file is reused. A directory that already holds it is returned without a request.
  • Calls for the same file take turns within one process.
  • Tests: 12 in update/download_resume_test.go.

The full description, the verification and the cost are in the upstream PR: vivaui#324.

Lithe's side, in the Lithe PR that moves the pin:

  • A cut-off patch is resumed, not replaced by the full archive.
  • The update cache keeps one version.
  • The marketplace plugin download gets the same resume and stall bound, in Lithe's own code.

Branches

Tests

On this branch, macOS 27 / arm64:

  • gofmt -l . is clean. go vet ./... passes, and so do GOOS=windows and GOOS=linux go vet ./update/ ./internal/... ./app/.
  • go test ./... -count=1: 90 packages pass. The only failure is cmd/viva: its 14 packaging tests say the program was built for macOS 13.0 or later but [mac] min_system says 12.0. They fail the same way on fork main 97fdbdd without this change, because of the local toolchain.
  • go test -race ./update/ -run TestDownload -count=20 passes.
  • Lithe's desktop tests with this source: desktop-go.sh test -race ./..., 58 packages pass. They ran through a go.work replace whose update sources are byte-identical to this branch; only the new 416 test was missing there.

This PR needs merging before Lithe can use it: Lithe's updater now depends on update.ErrInterrupted. Merging it, and moving Lithe's desktop/go.mod pin to the merge result, are left to the maintainers.

Download and DownloadPatch wrote to a fresh temporary file and removed it on
any failure, so a dropped connection threw away everything that had arrived
and the next call started from byte zero. Nothing bounded a transfer that
went silent either: the archive client has no total timeout, so a connection
that stopped delivering held the call until the caller's context ended.

Keep the bytes in a hidden file named by the feed's digest, and continue it
with a Range request on the next call. A 206 is appended only when its
Content-Range is exactly the bytes asked for; a 200 starts the file over, and
a 206 for another part or a 416 asks once more for the whole file. The whole
file is hashed again before it is kept, and a resumed file that fails the
check is fetched once from scratch, so a partial a crash left behind cannot
end up in the archive. A refusal still leaves no file behind.

A transfer that stops part way now wraps the new ErrInterrupted: a failed
connection, nothing arriving for a minute, 408, 429 or 5xx, or the end of
ctx (wrapping its error too). An untrusted certificate and a redirect off
HTTPS are not interruptions. A directory that already holds the verified file
is returned without a request, and calls for the same file in one process
take turns instead of writing the same partial.
@xiaoyumuxi

Copy link
Copy Markdown
Author

Superseded: upstream merged the same change as b17e605 (vivaui#324), and #29 brought it onto fork main (25d7106). Closing without merging.

@xiaoyumuxi xiaoyumuxi closed this Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant